<template>
    <div>
        <div class="outmain ba_f heighthv pad_20 bor_rad5">
            <div class="shuju_title mar_b20">
                <div class="shuju_title_text">
                    <span>生日有礼活动设置</span>
                </div>
            </div>
            <div class="mar_t20 flex-bet flex-y-top">
                <div class="flex-g-1">
                    <el-form ref="form" :model="form" label-width="180px">
                        <el-form-item label="发放时间" :required='true'>
                            <div class="numberInput">
                                <span class="mar_lr10">生日前</span>
                                <el-input-number v-model="form.day" controls-position="right" :min="1" :max="99999999"
                                                 class=""></el-input-number>
                                <span class="mar_lr10">天</span>
                            </div>
                            <div class="yb_margin lh16">备注：用户会在发奖时间收到奖品到账的消息通知</div>
                        </el-form-item>
                        <el-form-item label="手机短信" :required='true'>
                            <el-switch v-model="form.smsOpen" active-value="1" inactive-value="2" active-text="开启" inactive-text="关闭"></el-switch>
                            <div class="yb_margin lh16">开启后将通过短信发送祝福通知</div>
                        </el-form-item>
                    </el-form>
                </div>
            </div>
        </div>
        <div class="mar_t20 ba_f pad_20 t_c">
            <el-button type="primary" @click="submitForm">保存</el-button>
        </div>
        <attachment-img ref="img1" type="img" @attachment='imgadd1'></attachment-img>
    </div>
</template>
<script>
    import {getConfig, postConfig} from "@/api/setup";
    import attachmentImg from "@/plugins/attachment-img";

    export default {
        created() {
            this.init();
        },
        components: {attachmentImg,},
        data() {
            return {
                form: {
                    day: '',
                    smsOpen: '1',
                },
            }
        },
        methods: {
            async init() {
                const {data} = await getConfig({ident: 'birthday'});
                this.form2 = this.form
                this.form = Object.assign(this.form2, data);
                this.bus.$emit('loading', false)
            },
            enter(i=0){
                this.$refs['imgicon' + i].style.display = 'none'
            },
            leave(i=0){
                this.$refs['imgicon' + i].style.display = 'inline-block'
            },
            test(i = 0) {
                console.log(this.$refs, i)
                this.$refs['img' + i].dialogVisible = true
            },
            imgadd1(url) {
                this.form.icon = url.str
            },
            deleteMultiImage(item, index, type) {
                //typem没传是单图multigraph多图；index上传图片组件排序
                Array.prototype.remove = function (val) {
                    var index = this.indexOf(val);
                    if (index > -1) {
                        this.splice(index, 1);
                    }
                };
                if (type == 'multigraph') {
                    switch (index) {
                        case 2:
                            this.form2.environment.remove(item);
                            break
                    }
                } else {
                    switch (index) {
                        case 1:
                            this.form.icon = '';
                            break
                    }
                }
            },
            async submitForm() {
                this.$refs["form"].validate(async (valid) => {
                    if (valid) {
                        this.form.ident = 'birthday'
                        this.form.identName = '生日有礼设置'
                        const {msg} = await postConfig(this.form);
                        this.$baseMessage(msg, "success");
                        this.$router.go(-1)
                        this.init();
                    } else {
                        return false;
                    }
                });
            },
        }
    }
</script>
